package com.zhxt.web.controller.zhxtapi;

import com.zhxt.common.core.controller.BaseController;
import com.zhxt.common.core.domain.AjaxResult;
import com.zhxt.common.utils.StringUtils;
import com.zhxt.system.domain.ZhxtHxwh;
import com.zhxt.system.service.IHxwhService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 核心文化
 *
 * @author zhxt
 */
@RestController
@RequestMapping("/zhxtapi/hxwh")
public class HxwhController extends BaseController {

    @Autowired
    private IHxwhService iHxwhService;
    /**
     * 获取指定板块的核心文化内容
     */
    @PutMapping("/gethxwh")
    public AjaxResult getHxwhContent(String mkcode){
        AjaxResult ajaxResult= AjaxResult.success();
        String hxwhContent = iHxwhService.getHxwhContent(mkcode);
        if(StringUtils.isNotEmpty(hxwhContent)){
            ajaxResult.put("hxwh",hxwhContent);
        }
        return ajaxResult;
    }

    /**
     * 获取核心文化列表
     */
    @PostMapping("getHxwhList")
    public AjaxResult getHxwhList(){
        AjaxResult ajax=AjaxResult.success();
        List<ZhxtHxwh> hxwhList = iHxwhService.getHxwhList();
        if(hxwhList!=null&& !hxwhList.isEmpty()){
            ajax.put("hxwhList", hxwhList);
        }
        return ajax;
    }

    /**
     * 修改核心文化内容
     */
    @PostMapping("updateHxwh")
    public AjaxResult updateHxwh(String mkcode,String hxwh){
        AjaxResult ajax=AjaxResult.success();
        if(mkcode.isEmpty() || mkcode.equals(null)){
            return AjaxResult.error("模块代码不能为空");
        }
        int uNum=iHxwhService.updateHxwh(mkcode,hxwh);
        if(uNum > 0){
            ajax.put("dcode","00");
            ajax.put("dresult","修改成功");
        }else{
            ajax.put("dcode","99");
            ajax.put("dresult","修改失败");
        }
        return ajax;
    }
}
